package com.imddy.spbatch001.utils.sql;

import java.util.List;

// ====== 条件类 ======
public class Condition {
    private final String field;
    private final String operator;
    private final Object value;
    private final boolean hasValue;

    public Condition(String field, String operator, Object value) {
        this.field = field;
        this.operator = operator;
        this.value = value;
        this.hasValue = true;
    }

    public Condition(String field, String operator, Object value, boolean hasValue) {
        this.field = field;
        this.operator = operator;
        this.value = value;
        this.hasValue = hasValue;
    }

    // 工厂方法：等于
    public static Condition eq(String field, Object value) {
        return new Condition(field, "=", value, true);
    }

    // 工厂方法：不等于
    public static Condition neq(String field, Object value) {
        return new Condition(field, "!=", value, true);
    }

    // 工厂方法：大于
    public static Condition gt(String field, Object value) {
        return new Condition(field, ">", value, true);
    }

    // 工厂方法：小于
    public static Condition lt(String field, Object value) {
        return new Condition(field, "<", value, true);
    }

    // 工厂方法：LIKE
    public static Condition like(String field, String value) {
        return new Condition(field, "LIKE", value, true);
    }

    // 工厂方法：IN
    public static Condition in(String field, List<?> value) {
        return new Condition(field, "IN", value, true);
    }

    // 工厂方法：IS NULL
    public static Condition isNull(String field) {
        return new Condition(field, "IS NULL", null, false);
    }

    // 工厂方法：IS NOT NULL
    public static Condition isNotNull(String field) {
        return new Condition(field, "IS NOT NULL", null, false);
    }

    // Getter 方法
    public String getField() {
        return field;
    }

    public String getOperator() {
        return operator;
    }

    public Object getValue() {
        return value;
    }

    public boolean hasValue() {
        return hasValue;
    }

    @Override
    public String toString() {
        return field + " " + operator;
    }
}
